package com.inwavetech.os.tests.sync.mock;

import com.inwavetech.os.entity.Os;
import com.inwavetech.os.entity.enummap.OsClosingStatusMap;
import com.inwavetech.os.entity.enummap.OsServiceOrderTypeMap;
import com.inwavetech.os.entity.enummap.OsStatusMap;
import com.inwavetech.os.entity.enummap.ProductDiagnosysMap;
import com.inwavetech.os.tests.sync.util.DateHandler;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by jgskin on 3/9/14.
 */
public class OsJson extends JSONObject {
    public OsJson(
            int id,
            OsStatusMap statusMap,
            OsClosingStatusMap closingStatusMap,
            OsServiceOrderTypeMap serviceOrderTypeMap,
            ProductDiagnosysMap productDiagnosysMap,
            DateHandler dateHandler) throws JSONException {
        put("id", Integer.toString(id));

        put("client", "client_value");
        put("store", "store_value");
        put("opener", "opener_value");
        put("origin", "origin_value");
        put("contact", "contact_value");
        put("authorization", "authorization_value");
        put("activated_user", "activated_user_value");
        put("finished_user", "finished_user_value");
        put("assignment", "assignment_value");
        put("assignment_time", "assignment_time_value");
        put("roundup", "roundup_value");
        put("future_observation", "future_observation_value");
        put("maintenance_observation", "maintenance_observation_value");
        put("service_justification", "service_justification_value");
        put("travel_justification", "travel_justification_value");
        put("roundup", "roundup_value");
        put("future_observation", "future_observation_value");
        put("name_responsible", "name_responsible_value");


        put("travel_price", "12.50");
        put("service_price", "200.60");

        put("status_id", statusMap.getId(Os.Status.ACTIVE));
        put("closing_status_id", closingStatusMap.getId(Os.ClosingStatus.CANCELED));
        put("service_order_type_id", serviceOrderTypeMap.getId(Os.ServiceOrderType.INSTALL));

        put("created_at", dateHandler.getDateStr());
        put("activated_at", dateHandler.getDateStr());
        put("assignment_date", dateHandler.getDateStr());
        put("updated_at", dateHandler.getDateStr());
        put("finished_at", dateHandler.getDateStr());

        JSONArray products = new JSONArray();

        int i = 3 * id + 1;
        int limit = i + 3;
        for (i=i; i < limit; i++) {
            products.put(new ProductJson(i, productDiagnosysMap, dateHandler));
        }

        put("products", products);
    }
}
